package net.xisberto.bustime;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;

public class ManageListActivity extends TabActivity implements OnTabChangeListener {
	private final String
		TAB_ADD = "add",
		TAB_REM = "rem";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_manage_list);
		
		Resources res = getResources();
		TabHost tabHost = getTabHost();
		TabHost.TabSpec tabSpec;
		Intent tabIntent;
		TextView indicator;
		View view = LayoutInflater.from(this).inflate(R.layout.view_tab_widgets, null);
		LinearLayout layout_tab_spec = (LinearLayout) view.findViewById(R.id.linearLayout_tab_widgets);
		
		//Tab AddBusActivity
		indicator = (TextView) view.findViewById(R.id.tab_text_add);
		layout_tab_spec.removeView(indicator);
		indicator.setText(R.string.text_tab_add_bus);
		tabIntent = new Intent().setClass(this, AddBusActivity.class);
		tabSpec = tabHost.newTabSpec(TAB_ADD)
				.setIndicator(indicator)
				.setContent(tabIntent);
		tabHost.addTab(tabSpec);
		
		//Tab PersonalListActivity
		indicator = (TextView) view.findViewById(R.id.tab_text_rem);
		layout_tab_spec.removeView(indicator);
		indicator.setText(R.string.text_tab_rem_bus);
		tabIntent = new Intent().setClass(this, PersonalListActivity.class);
		tabSpec = tabHost.newTabSpec(TAB_REM)
				.setIndicator(indicator)
				.setContent(tabIntent);
		tabHost.addTab(tabSpec);

		tabHost.setOnTabChangedListener(this);
		tabHost.setCurrentTabByTag(TAB_ADD);
		this.onTabChanged(TAB_ADD);
	}

	@Override
	public void onTabChanged(String tabId) {
		if (tabId.equals(TAB_ADD)) {
			this.getTabWidget().getChildTabViewAt(0).findViewById(R.id.tab_text_add).setBackgroundResource(R.drawable.gradient_tab_widgets_down);
			this.getTabWidget().getChildTabViewAt(1).findViewById(R.id.tab_text_rem).setBackgroundResource(R.drawable.gradient_tab_widgets);
		} else if (tabId.equals(TAB_REM)) {
			this.getTabWidget().getChildTabViewAt(0).findViewById(R.id.tab_text_add).setBackgroundResource(R.drawable.gradient_tab_widgets);
			this.getTabWidget().getChildTabViewAt(1).findViewById(R.id.tab_text_rem).setBackgroundResource(R.drawable.gradient_tab_widgets_down);
		}
	}
	

}
